package com.um.jdy.platform.member.controller;

import com.um.jdy.common.member.entity.dto.WalletDTO;
import com.um.jdy.common.member.entity.po.Wallet;
import com.um.jdy.platform.member.entity.dto.WalletBillPageDTO;
import com.um.jdy.platform.member.entity.dto.MemberPageDTO;
import com.um.jdy.platform.member.entity.vo.WalletItemVO;
import com.um.jdy.platform.member.manager.MemberWalletManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 会员管理
 *
 * @author cs
 * 日期 2023/5/25
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "会员钱包")
@Validated
@RestController
@RequestMapping("/api/v1/cms/member/wallet")
@ApiPermission("wallet")
@TokenRequired
public class MemberWalletController extends BaseController<MemberWalletManager> {

    /**
     * 分页查询会员钱包
     *
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询会员钱包")
    @PostMapping("page")
    public Response<Page<WalletItemVO>> page(@RequestBody MemberPageDTO params){
        PageParams pageParams =  params.toPageParams(new String[]{"mobile","nickname","no"},new String[]{"u.mobile","u.nickname","u.no"});
        return manager.page(pageParams);
    }

    /**
     * 钱包明细
     * @param params
     * @return
     */
    @ApiPermission("bill_page")
    @ApiOperation("分页查询钱包明细")
    @PostMapping("bill_page")
    public Response<Page<Wallet>> billPage(@Valid @RequestBody WalletBillPageDTO params) {

        PageParams pageParams = params.toPageParams(
                new String[]{"no","orderNo","userId","event","type"},
                new String[]{"no","order_no","member_user_id","event","type"},
                "create_time","beginTime","endTime");
        pageParams.getCondition().put("orderby", "create_time asc,id asc");
        return manager.billPage(pageParams);
    }

    @ApiPermission("add")
    @ApiOperation("新增")
    @PostMapping
    public Response<Wallet> add(@Valid @RequestBody WalletDTO dto) {
        return manager.addEntity(dto);
    }
}
